
package com.test.pdproject.util;

/**
 * app接口响应数据格式
 * @author Administrator
 *
 */
public class AppResponse {
	/**
	 * 状态码
	 */
	private String code;
	/**
	 * 消息
	 */
	private String msg;
	/**
	 * 结果集
	 */
	private Object data;

	private AppResponse(String code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public AppResponse(String code, Object data) {
		this(code, null, data);
	}

	public AppResponse(String code, String msg) {
		this(code, msg, null);
	}

	/**
	 * 返回 用户输入参数错误的AppResponse
	 *
	 * @param msg
	 * @return
	 */
	public static AppResponse paramError(String msg) {
		return new AppResponse(StateEnum.AppResponseState.PARAM_ERROR.getName(), msg, null);
	}
	public static AppResponse paramError(String msg,Object data) {
		return new AppResponse(StateEnum.AppResponseState.PARAM_ERROR.getName(), msg, data);
	}

	/**
	 * 返回 用户请求错误的AppResponse
	 * @param msg
	 * @return
	 */
	public static AppResponse error(String msg) {
		return new AppResponse(StateEnum.AppResponseState.ERROR.getName(), msg, null);
	}
	/**
	 * 返回 用户请求错误的AppResponse
	 * @param msg
	 * @return
	 */
	public static AppResponse error(String msg,Object data) {
		return new AppResponse(StateEnum.AppResponseState.ERROR.getName(), msg, data);
	}

	/**
	 * 请求成功
	 * @param data
	 * @return
	 */
	public static AppResponse success(Object data) {
		return new AppResponse(StateEnum.AppResponseState.SUCCESS.getName(), data);
	}

	/**
	 * 请求成功，没有响应data参数
	 * @param
	 * @return
	 */
	public static AppResponse success() {
		return new AppResponse(StateEnum.AppResponseState.SUCCESS.getName(), null, null);
	}

	public static AppResponse noPermission(String msg) {
		return new AppResponse(StateEnum.AppResponseState.NO_PERMISSION.getName(), msg, null);
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
